import { readFileSync } from 'fs';
import * as yaml from 'js-yaml';
import { join } from 'path';
import * as _ from 'lodash';

const YAML_COMMON_CONFIG_FILENAME = 'config.yml';
const filePath = join(__dirname, '../config', YAML_COMMON_CONFIG_FILENAME);
const env = process.env.NODE_ENV || 'development';
const envFilePath = join(__dirname, '../config', `config.${env}.yml`);

const commonConfig = yaml.load(readFileSync(filePath, 'utf8'));
const envConfig = yaml.load(readFileSync(envFilePath, 'utf8'));

export default () => {
  return _.merge(commonConfig, envConfig);
}